<template>
    <div class="w100 h100">
        <add v-if="type === 'create'" @tabChange="tabChange" :applyNeedData="applyNeedData" :isEdit="isEdit"></add>
        <Table v-if="type === 'list'" @tabChange="tabChange"></Table>
    </div>
</template>

<script>
import Add from './checkComponents/Add.vue'
import Table from './checkComponents/Table.vue'
import { applyApi, checkApi } from '../../common/api/applyManage'
import Bus from '@/common/bus.js'

export default {
    components: {
        Add,
        Table,
    },
    data() {
        return {
            type: 'list',
            applyNeedData: null,
            isEdit: true,
        }
    },
    mounted() {
        let id = new URL(window.location.hash.substr(1), window.location)?.searchParams?.get('id')
        if (id) {
            this.type = null
            this.loadDetail(id)
        }
    },
    methods: {
        tabChange(type, value, isEdit) {
            this.type = type
            this.applyNeedData = value
            this.isEdit = isEdit
        },
        async loadDetail(id) {
            Bus.$emit('loadingStateChange', true)
            try {
                let res = await applyApi.detail({ id: id, state: 1 })
                if (res.code == 200) {
                    this.tabChange('create', { record: res.data }, true)
                }
            } catch (e) {
                console.log(e)
            }
            Bus.$emit('loadingStateChange', false)
        },
    },
}
</script>

<style lang="scss" scoped></style>
